import 'package:flutter/material.dart';
import 'package:ycbl/config/bl_color.dart';
import 'package:ycbl/config/bl_style.dart';
import 'package:ycbl/model/learn_task_list_entity.dart';
import 'package:ycbl/common/bl_live_status.dart';
import 'package:ycbl/utils/live_helper.dart';
import 'package:ycbl/utils/toast_util.dart';

class BLLearnTaskItem extends StatelessWidget {

  final int index;
  final LearnTaskEntity task;

  const BLLearnTaskItem({Key key, @required this.task, @required this.index}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var liveStatus = task.liveStatus();
    //默认灰色
    Color liveColor = BLColor.commonGreyTextColor;
    if (liveStatus == BLLiveStatus.LIVING) {
      liveColor = BLColor.orangeLabelColor;
    }else if (liveStatus == BLLiveStatus.REPLAY) {
      liveColor = BLColor.commonRedTextColor;
    }

    return GestureDetector(
      child: Container(
        alignment: Alignment.center,
        padding: EdgeInsets.symmetric(horizontal: 16,),
        decoration: BoxDecoration(
          border: Border(bottom: BorderSide(width: 0.5, color: BLColor.commonDividerColor,),),
        ),
        child: Row(
          children: [
            Container(
              width: 20,
              height: 20,
              alignment: Alignment.center,
              margin: EdgeInsets.only(right: 16,),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(20),),
                color: Color(0xFFEDEDED),
              ),
              child: Text('${index+1}', style: BLStyle.smallTextStyle,),
            ),

            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisSize: MainAxisSize.min,
                children: [
                  Text(task.courseName ?? '', style: BLStyle.commonBlackTextStyle,),
                  SizedBox(height: 8,),
                  Text(task.subDesc, style: BLStyle.smallTextStyle,),
                ],
              ),
            ),

            SizedBox(width: 16,),
            Text(
              liveStatus.liveString,
              style: BLStyle.smallGreyTextStyle.copyWith(color: liveColor),
            ),
          ],
        ),
      ),
      onTap: (){
        if (task.isClassIn()) {
          ToastUtil.showShortToast('在不支持 ClassIn，敬请期待');
        }else {
          LiveHelper.startGensee(task.stuUrl, task.liveToken,
              task.vodUrl, task.vodToken, task.startDateTime, task.endDateTime);
        }

      },
    );
  }
}
